package com.jeespring.order.controller;

import com.jeespring.dto.String;
import com.jeespring.entity.Pay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/lb/order")
public class OrderController {

    public static final String PAY_SERVICE = "http://spring-cloud-pay/";

    @Resource(name = "LBRestTemplate")
    private RestTemplate template;

    @PostMapping("/insert")
    public String insert(){
        Pay pay = new Pay();
        pay.setOrderId(1L);
        pay.setMoney(100L);
        String String = template.postForObject(PAY_SERVICE, pay, String.class);
        return String;
    }

    @GetMapping("/get/{id}")
    public String selectById(@PathVariable Long id){
        String String = template.getForObject(PAY_SERVICE + "/pay/get/" + id, String.class);
        return String;
    }
}
